<template>
  <div class="my_div">
    <img :src="src" alt="" />
    <p @click="selBtn" :style="{ backgroundColor: color }">
      {{ title }}
    </p>
  </div>
</template>

<script>
export default {
  data() {
    return {
      bool: true,
      color: '',
      r: '',
      g: '',
      b: '',
    }
  },
  props: ['src', 'title', 'index'],
  methods: {
    selBtn() {
      this.r = Math.floor(Math.random() * 255)
      this.g = Math.floor(Math.random() * 255)
      this.b = Math.floor(Math.random() * 255)
      this.color = 'rgb' + '(' + this.r + ',' + this.g + ',' + this.b + ')'
      console.log(this.color)
      this.$emit('doge', this.index)
    },
  },
}
</script>

<style>
.my_div {
  width: 200px;
  border: 1px solid black;
  text-align: center;
  float: left;
}

.my_div img {
  width: 100%;
  height: 200px;
}
p.color {
  background-color: rgb(r, g, b);
}
</style>
